package com.propertyportal.alladapter;

import java.util.List;

import com.personhelper.PersonHelper;
import com.propertyportal.manageproperty.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PropertyAgentListAdapter extends BaseAdapter{

	Context mcontext;
	LayoutInflater inflater;
	private List<PersonHelper> agentlist = null;
	//private ArrayList<AgentHelper> filter;

	public PropertyAgentListAdapter(Context context, List<PersonHelper> agentlist) {
		mcontext = context;
		this.agentlist = agentlist;
		inflater = LayoutInflater.from(mcontext);
	}

	public class ViewHolder {
		TextView name;
		TextView number;
		TextView email;
	}

	@Override
	public int getCount() {
		return agentlist.size();
	}

	@Override
	public PersonHelper getItem(int position) {
		return agentlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View view, ViewGroup parent) {
		final ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.expandablelistview_agent_title, null);
			// Locate the TextViews in listview_item.xml
			holder.name = (TextView) view.findViewById(R.id.property_agent_name);
			holder.email = (TextView) view.findViewById(R.id.property_agent_address);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		// Set the results into TextViews
		holder.name.setText(agentlist.get(position).getFirstName()+" "+ agentlist.get(position).getLastName());
		holder.email.setText(agentlist.get(position).getEmailAddress());
		
		// Listen for ListView Item Click
		
		return view;
	}
}
